<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport"
        content="width=device-width, initial-scale=1.0,maximum-scale=1, minimum-scale=1, user-scalable=no" />
    <meta name="format-detection" content="telephone=no" />
    <title>修改交易密码</title>
    <link rel="stylesheet" href="../../css/reset.css">
    <style>
        body {
            width: 100%;
            background-color: #fff;
            font-size: 0.28rem;
            height: auto;
            -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
            font-family: PingFangSC-Regular, sans-serif;
            color: #333333;
        }

        .showinput input {
            outline: none;
            border: none;
            background-color: #fff;
        }

        .showinput button {
            outline: none;
            border: none;
            background-color: #ffd203;
        }

        .showinput ul li {
            width: 100%;
            padding-left: 0.29rem;
            box-sizing: border-box;
        }

        .showinput ul li p {
            width: 100%;
            height: 0.92rem;
            display: flex;
            display: -webkit-flex;
            justify-content: space-between;
            align-items: center;
            padding-right: 0.42rem;
            box-sizing: border-box;
            border-bottom: 1px solid #e2e2e2;
        }

        .showinput ul li input {
            flex: 1;
            text-align: right;
            height: 0.76rem;
            padding-left: 0.2rem;
            font-size: 0.26rem;
            box-sizing: border-box;
        }

        .showinput ul li:last-of-type input {
            text-align: center;
        }

        input::placeholder {
            color: #d9d9d9;
        }

        .showinput ul li:last-of-type {
            border-top: 0.2rem solid #f7f7f7;
        }

        .showinput ul li:last-of-type p button {
            width: 1.8rem;
            height: 0.68rem;
            text-align: center;
            line-height: 0.68rem;
            border-radius: 0.1rem;
            font-size: 0.24rem;
        }

        #setPassword {
            width: 6.9rem;
            height: 0.88rem;
            line-height: 0.88rem;
            text-align: center;
            border-radius: 0.1rem;
            margin-left: calc((100% - 6.9rem) / 2);
            margin-top: 0.86rem;
            font-size: 0.26rem;
            color: #181818;
            background-color: #e5e5e5;
        }
    </style>
</head>

<body>
    <div class="showinput">
        <ul>
            <li>
                <p>
                    <span>
                        原交易密码
                    </span>
                    <input type="password" id="oldPass" maxlength="6" oninput="this.value=this.value.replace(/\D/g, '')"
                        placeholder="请输入您的交易密码" onpaste="return false" oncontextmenu="return false"
                        oncopy="return false" oncut="return false">
                </p>
            </li>
            <li>
                <p>
                    <span>
                        新交易密码
                    </span>
                    <input type="password" id="firstAddPass" maxlength="6"
                        oninput="this.value=this.value.replace(/\D/g, '')" placeholder="请输入新的交易密码"
                        onpaste="return false" oncontextmenu="return false" oncopy="return false" oncut="return false">
                </p>
            </li>
            <li>
                <p>
                    <span>
                        确认新密码
                    </span>
                    <input type="password" id="secondAddPass" maxlength="6"
                        oninput="this.value=this.value.replace(/\D/g, '')" placeholder="请再次确认新交易密码"
                        onpaste="return false" oncontextmenu="return false" oncopy="return false" oncut="return false">
                </p>
            </li>
            <li>
                <p>
                    <span style="display: block;width:1.8rem;">
                        手机验证码
                    </span>
                    <input type="text" id="getSaftCode" maxlength="6" oninput="this.value=this.value.replace(/\D/g, '')"
                        placeholder="请输入验证码">
                    <button id="getMessage">
                        获取验证码
                    </button>
                </p>
            </li>
        </ul>
        <button id="setPassword" disabled>
            设置交易密码
        </button>
    </div>
    <script src="../../script/autosize.js"></script>
    <script src="../../script/jquery_three_two_one.js"></script>
    <script src="../../script/fastclick.js"></script>
    <script src="../../script/app.js"></script>
    <script>
        apiready = function () {
            var app = new APP();
            var account = app.getAccount();
            var getCnySms, isCnyCaptcha = 0;
            if (app.ST == "ios") {
                $("input").click(function () {
                    $(this)
                        .focus()
                        .select(); //保险起见，还是加上这句。
                });
            }
            $("input").on("input propertychange", function () {
                var firstPass = $("#firstAddPass").val().trim();
                var secondPass = $("#secondAddPass").val().trim();
                var getSaftCode = $("#getSaftCode").val().trim();
                var olderPass = $("#oldPass").val().trim();
                if (firstPass && secondPass && getSaftCode && olderPass) {
                    $("#setPassword").prop("disabled", false).css("backgroundColor", "#ffd203");
                } else {
                    $("#setPassword").prop("disabled", true).css("backgroundColor", "#e5e5e5");
                }
            });

            function getCodeCallback() {
                app.countDown(60, function (value) {
                    if (value.time != 0) {
                        $("#getMessage").text(value.time + "s");
                    } else {
                        _fmOpt.reset();
                        $("#getMessage").text("重新获取").attr("disabled", false).bind("click");
                    }
                });
                app.getSmslogin({
                    blackBox: isCnyCaptcha == 1 ? _fmOpt.getinfo() : "",
                    yzm_token: getCnySms
                }, function (ret) {
                    if (ret.code == 200) {
                        app.toast("发送成功");
                    } else {
                        app.toast(ret.message);
                    }
                })
            }


            //CNY 同盾插件初始化
            _fmOpt = {
                display: 'bind', //popup方式渲染验证码
                container: '#getMessage', //验证码button渲染的目标DOM，自动展现方式下必需，详情见后文
                area: '', //对于custom模式，弹出窗口的加载容器，详情见后文
                partner: "renrenkj",
                appName: "renrenkj_h5",
                width: "",
                height: "",
                fmb: true,
                initialTime: new Date().getTime(),
                token: "renrenkj" + "-" + new Date().getTime() + "-" + Math.random().toString(16).substr(2),
                env: 1,
                getinfo: function () {
                    return "e3Y6ICIyLjUuMCIsIG9zOiAid2ViIiwgczogMTk5LCBlOiAianMgbm90IGRvd25sb2FkIn0=";
                }
            };
            var fm = document.createElement('script');
            fm.type = 'text/javascript';
            fm.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'static.tongdun.net/captcha/main/tdc.js?ver=1.0&t=' + (new Date().getTime() / 600000).toFixed(0);
            var s = document.getElementsByTagName('script')[0];
            s.parentNode.insertBefore(fm, s);
            _fmOpt.beforeValidate = function () {
                $("#getMessage").attr("disabled", true).unbind("click");
                app.checkIsMechine("sms", function (ret, err) {
                    if (ret.code == 200) {
                        isCnyCaptcha = ret.data;
                        if (isCnyCaptcha == 1) {
                            _fmOpt.onSuccess = function (validateToken) {
                                if (validateToken) {
                                    getCnySms = validateToken;
                                    getCodeCallback();
                                } else {
                                    _fmOpt.reset();
                                }
                            };
                            return true;
                        } else {
                            getCodeCallback();
                            return false
                        }
                    }
                })
                return true
            }
            _fmOpt.onClose = function (params) {
                $("#getMessage").text("获取验证码").attr("disabled", false).bind("click");
            }
            $("#setPassword").on("click", function () {
                var checkFirst = $("#firstAddPass").val().trim();
                var checkSecond = $("#secondAddPass").val().trim();
                var getCode = $("#getSaftCode").val().trim();
                var olderPassCheck = $("#oldPass").val().trim();
                if (olderPassCheck.length < 6) {
                    app.toast("原交易密码不足6位");
                    return
                }
                if (checkFirst.length < 6) {
                    app.toast("交易密码不足6位");
                    return
                }
                if (checkSecond.length < 6) {
                    app.toast("确认密码不足6位");
                    return
                }
                if (checkFirst !== checkSecond) {
                    app.toast("两次密码不一致");
                    return
                }
                if (getCode.length < 6) {
                    app.toast("请输入6位验证码");
                    return
                }
                app.ajaxPro({
                    url: "member/edit-transaction-pwd",
                    values: {
                        token: account.token,
                        transactionPassword: olderPassCheck,
                        newTransactionPassword: checkFirst,
                        smscaptcha: getCode
                    },
                    openFlower: true
                }, function (ret) {
                    if (ret.code == 200) {
                        app.toast("交易密码修改成功");
                        setTimeout(function () {
                            app.closeW();
                        }, 2000)
                    } else {
                        app.toast(ret.message);
                    }
                })
            })
        }
    </script>
</body>

</html>